'use strict';

describe('ruleDataFilter', function() {
  var $test, $save;

  beforeEach(module('fbdApp.ruleModule'));
  beforeEach(inject(function(_$filter_) {
    $test = _$filter_('testRuleFilter');
    $save = _$filter_('saveRuleFilter');
  }));

  it('should be defined', function(done) {
    expect($test).toBeDefined();
    expect($save).toBeDefined();
    return done();
  });

  describe('test filter', function() {

    // 分两种情况(三种模式都要测)：
    // 1.测试内容为文件
    // 2.测试内容为文本

    var tempData1 = {
      name: 'rule1',
      type: '1',
      beginText: '<<<',
      endText: 'sd',
      limit: '5',
      similar: '5',
      mode: 'signs'
    };

    var tempData2 = {
      name: 'rule2',
      type: '2',
      beginText: '<<<',
      endText: 'sd',
      limit: '5',
      similar: '5',
      mode: 'signs'
    };

    var tempData3 = {
      name: 'rule3',
      type: '3',
      beginText: '<<<',
      endText: 'sd',
      limit: '5',
      similar: '5',
      mode: 'signs'
    };

    var testFile = {
      type: 'file',
      content: 'abc.fbd'
    };

    var testText = {
      type: 'string',
      content: 'abc123'
    };

    describe('test with file', function() {
      it('test type 1', function(done) {

        var postData = {
          rule: {
            mode: 'signs',
            beginText: '<<<',
            type: 1,
            limit: 5,
            similar: 5
          },
          text: {
            type: 'file',
            content: 'abc.fbd'
          }
        };
        expect($test(tempData1, testFile)).toEqual(postData);
        return done();
      });

      it('test type 2', function(done) {
        var postData = {
          rule: {
            mode: 'signs',
            beginText: '<<<',
            endText: 'sd',
            type: 2,
            limit: 5,
            similar: 5
          },
          text: {
            type: 'file',
            content: 'abc.fbd'
          }
        };
        expect($test(tempData2, testFile)).toEqual(postData);
        return done();
      });

      it('test type 3', function(done) {
        var postData = {
          rule: {
            mode: 'signs',
            beginText: '<<<',
            type: 3,
            limit: 5,
            similar: 5
          },
          text: {
            type: 'file',
            content: 'abc.fbd'
          }
        };
        expect($test(tempData3, testFile)).toEqual(postData);
        return done();
      });
    });

    describe('test with text', function() {
      it('test type 1', function(done) {

        var postData = {
          rule: {
            mode: 'signs',
            beginText: '<<<',
            type: 1,
            limit: 5,
            similar: 5
          },
          text: {
            type: 'string',
            content: 'abc123'
          }
        };
        expect($test(tempData1, testText)).toEqual(postData);
        return done();
      });

      it('test type 2', function(done) {
        var postData = {
          rule: {
            mode: 'signs',
            beginText: '<<<',
            endText: 'sd',
            type: 2,
            limit: 5,
            similar: 5
          },
          text: {
            type: 'string',
            content: 'abc123'
          }
        };
        expect($test(tempData2, testText)).toEqual(postData);
        return done();
      });

      it('test type 3', function(done) {
        var postData = {
          rule: {
            mode: 'signs',
            beginText: '<<<',
            type: 3,
            limit: 5,
            similar: 5
          },
          text: {
            type: 'string',
            content: 'abc123'
          }
        };
        expect($test(tempData3, testText)).toEqual(postData);
        return done();
      });
    });


  });

  // describe('save filter', function() {
  //   var tempData = {
  //     mode: 'signs',
  //     beginText: '<<<',
  //     type: 1,
  //     expression: '12345, 11512'
  //       // name: 'rule1'
  //   };
  //
  //   var addData = {
  //     mode: 'signs',
  //     beginText: '<<<',
  //     type: 1,
  //     expression: '12345, 11512',
  //     name: 'rule1'
  //   };
  //   it('test rule filter', function(done) {
  //     expect($save(tempData)).toEqual(addData);
  //     return done();
  //   });
  // });

});
